Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Data
Imports System.Drawing
Imports System.Linq
Imports System.Text
Imports System.Windows.Forms
Imports System.Management

' some of this files has been copied from http://www.codeproject.com/KB/cs/my_explorer.aspx 
' and the forums pages below
Public Partial Class DbfSamples
	Inherits Form
	Public Sub New()
		InitializeComponent()
        Dim fi As IO.FileInfo = New System.IO.FileInfo(Application.ExecutablePath)
		FillTree(tvFolders.Nodes, fi.Directory)
		tvFolders.ExpandAll()
	End Sub

	Private Function FillTree(treeNodeCollection As TreeNodeCollection, directoryInfo As System.IO.DirectoryInfo) As Boolean
		Dim seenSomething As Boolean = False
		For Each di As System.IO.DirectoryInfo In directoryInfo.GetDirectories()
			If FillTree(treeNodeCollection, di) Then
				seenSomething = True
			End If
		Next
		For Each fi As System.IO.FileInfo In directoryInfo.GetFiles()
			Select Case fi.Extension.ToLower()
				Case ".dbf"
					treeNodeCollection.Add(New FileInfoNode(fi))
					seenSomething = True
					Exit Select
			End Select
		Next
		Return seenSomething
	End Function

	Private Sub Form1_Load(sender As Object, e As EventArgs)

	End Sub

	Private Sub tvFolders_AfterSelect(sender As Object, e As TreeViewEventArgs)
        Dim finode As FileInfoNode = TryCast(e.Node, FileInfoNode)
		If finode IsNot Nothing Then
			dbfTableView1.DbfTable = New DbfDotNet.DbfTable(finode.FileInfo.FullName, System.Text.Encoding.UTF8, DbfDotNet.DbfVersion.dBaseIV)
		End If
	End Sub


End Class
